<%@ page contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>质检管理</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <jsp:include page="${pageContext.request.contextPath }/resource_path.jsp" flush="true"/>
</head>
<body class="layui-anim layui-anim-up">
<div class="x-nav">
	<span class="layui-breadcrumb">
	  <a href="">首页</a>
	  <a>
	    <cite>质检管理</cite>
	  </a>
	</span>
</div>
<!-- 上表 -->
  <div class="x-body">
     <div>
		<div class="layui-inline">
			<table>
				<tr>
					<td>
						<input class="layui-input" id="qcp" placeholder="请输入SAP/QAD" autocomplete="off" style="display: inline; width: 180px; margin-left: 10px">
					</td>
					<td>
						<div class="layui-form" style="width: 180px; margin-left: 10px">
							<select id="scheck" name="scheck">
								<option value="">是否质检</option>
								<option value="1">否</option>
								<option value="0">是</option>
							</select>
						</div>
					</td>
					<td class="layui-input-inline">
						<input class="layui-input" id="startTime" placeholder="请输入开始时间" autocomplete="off" style="display: inline; width: 180px; margin-left: 10px"> -
						<input class="layui-input" id="endTime" placeholder="请输入结束时间" autocomplete="off" style="display: inline; width: 180px"> 
					</td>
				</tr>
			</table>
		</div>
        <button class="layui-btn layui-btn-normal" data-type="reload1"><i class="layui-icon layui-icon-search"></i>检索</button>
	  </div>
	  </div>
	<table class="layui-hide" id="tableDetails" lay-filter="tableDetails"></table>
	<!-- 下表 -->
	<table class="layui-hide" id="tableDetailsSub" lay-filter="tableDetailsSub"></table>
<script type="text/javascript">
layui.use(['table','layer','upload','form','laydate'], function(){
	var table = layui.table;
	var layer = layui.layer,
    form = layui.form,
    laydate = layui.laydate
    
    //日期时间范围
	var minListDate = "1000-01-01 00:00:00";//最小可选时间，例：1990-02-01
    var maxListDate = "3000-12-31 23:59:59";//最大可选时间，例：2200-12-31   
    var enddate = laydate.render({
        elem: "#endTime",
        format: 'yyyy-MM-dd HH:mm:ss',
        type: 'datetime',
        min: minListDate,
        max: maxListDate,
        done: function (val, date) {
            if (date && date.year){
            	//设置结束时间 设置开始时间的最大值为结束时间
                begindate.config.max = {
                    year: date.year,
                    month: date.month - 1,//必须减1才是正确值
                    date: date.date,
                    hours: date.hours,
                    minutes: date.minutes,
                    seconds: date.seconds
                };
            }else {
            	//清除结束值    设置开始时间最大值
                var dateInit = new Date(maxListDate.replace(/-/g, "/"));
                begindate.config.max = {
                    year: dateInit.getFullYear(),
                    month: dateInit.getMonth(),
                    date: dateInit.getDate(),
                    hours: dateInit.getHours(),
                    minutes: dateInit.getMinutes(),
                    seconds: dateInit.getSeconds()
                };
            }
        }
    });
    var begindate = laydate.render({
        elem: "#startTime",
        format: 'yyyy-MM-dd HH:mm:ss',
        type: 'datetime',
        min: minListDate,
        max: maxListDate,
        done: function (val, date) {
            if (date && date.year){
            	//设置开始时间 设置结束时间的最小值为开始时间
                enddate.config.min = {
                    year: date.year,
                    month: date.month - 1,
                    date: date.date,
                    hours: date.hours,
                    minutes: date.minutes,
                    seconds: date.seconds
                };
            }else {
            	//清除开始值 ，设置结束值最小值
                var dateInit = new Date(minListDate.replace(/-/g, "/"));
                enddate.config.min = {
                    year: dateInit.getFullYear(),
                    month: dateInit.getMonth(),
                    date: dateInit.getDate(),
                    hours: dateInit.getHours(),
                    minutes: dateInit.getMinutes(),
                    seconds: dateInit.getSeconds()
                };
            }
        }
    });
    
	var $ = layui.jquery, active = {
			reload1:function () {
				var keyword01 = $("#qcp").val();
				
				var keyword02 = $("#scheck").val();
				
				var keyword03 = "";
				
				var startTime = $.trim($("#startTime").val());
				if(startTime != null && startTime != ""){
					keyword03 = keyword03 + " and check_date >= '"+startTime+""+"' ";
				}
				var endTime = $.trim($("#endTime").val());
				if(endTime != null && endTime != ""){
					keyword03 = keyword03 + " and check_date <= '"+endTime+"' ";
				}
				table.reload('contenttableDetails',{
					method:'get',
					where:{
					    keyword01:keyword01,
					    keyword02:keyword02,
					    keyword03:keyword03,
					   
					}
					,page: {
	                    curr: 1//重新从第 1 页开始
	                }
				});
			},
			
			
		}
	$('.layui-btn').on('click', function(){
        var type = $(this).data('type');
        active[type] ? active[type].call(this) : '';
    });
	 table.render({
         elem: '#tableDetails'
         ,url:'${pageContext.request.contextPath }/receiveDetail/queryReceiveDetailQualityCriteria.do'
         ,toolbar: '#toolbar'
         ,title: '质检明细表'
         ,id :'contenttableDetails'
         ,limits:[10,20,30]
         //,defaultToolbar:['filter', 'print']
         ,cols: [[
         	 {type: 'checkbox',fixed: 'left'},
             {field:'id', title:'序号', width: 50,type:'numbers', align:'center'},	
             {field:'mid', title:'物料id', align:'center', hide:true},
             {field:'pici', title:'批次', align:'center', width: 110},
             {field:'materiel_name', title:'物料名称', align:'center', width: 320/* ,
             	event: 'collapse',
                 templet: function(d) {
                     return '<div style="position: relative;'+'padding: 0 10px 0 20px;">' + d.materiel_name + '<i style="left: 0px;" lay-tips="展开" class="layui-icon layui-colla-icon layui-icon-right"></i></div>'
                 } */
             },
             {field:'materiel_num', title:'SAP/QAD', align:'center'},
            /*  {field:'brevity_num', title:'简码', align:'center'}, */
             {field:'packing_quantity', title:'包装数量', align:'center'},
             {field:'is_check', title:'是否质检', width: 100, align:'center'
                 ,templet: function(d){
                     var value = d.is_check;
                     if(value == 0){
                         return "是";
                     } else if (value == 1) {
                         return "否";
                     }
                 }
             },
           
             {field:'codeNum', title:'收货总数(个)', align:'center'},
             {field:'ng_num', title:'不良品个数(个)', align:'center'},
         	 {field:'check_date', title:'质检时间', align:'center', width: 200,
                templet: function(d){
                    return d.check_date ? layui.util.toDateString(d.check_date, 'yyyy-MM-dd HH:mm:ss') : '';
                }
			}
         ]]
         ,page: true
         ,done : function(res, curr, count){
         	//merge(res);
             $('th').css({
                 'background-color': '#009688', 'color': '#fff','font-weight':'bold',
             })
         }
     });
     /* 监听表格的展开行事件 */
     table.on('tool(tableDetails)', function(obj){
     	if (obj.event === 'collapse') {
     		//当前行
				var trObj = layui.$(this).parent('tr'); 
				//开启手风琴，那么在进行折叠操作时，始终只会展现当前展开的表格。
				var accordion = true 
				var content = '<table></table>' //内容
				//表格行折叠方法
				collapseTable({
					elem: trObj,
					accordion: accordion,
					content: content,
					success: function (trObjChildren, index) { //成功回调函数
						//trObjChildren 展开tr层DOM
						//index 当前层索引
						trObjChildren.find('table').attr("id", index);
                     //===================================start===================================
						table.render({
							elem: "#" + index
                         //,url:'${pageContext.request.contextPath }/receiveDetail/queryWorkloadByreceiveDetailQualityId.do?receiveDetailQuality_id=' + obj.data.id
                         ,url:'${pageContext.request.contextPath }/receiveDetail/queryCodemarkByReceiveDetailId.do?receive_detail_id=' + obj.data.id
                         ,title: 'machineList'
                         //,limits:[10,20,30]
                        	,cols:
							[[
	                            {field:'id', title:'序号', sort: true, width: 60, type:'numbers', align:'center'},
	                            //{field:'SAP_QAD',title: 'SAP_QAD',align:'center',},
	                            {field:'num', title: '数量', align:'center'},
	                            {field:'code', title: '条码', align:'center'},
                         ]]
                         ,page: false
						});
						//===================================end===================================
					}
				});
			}
     });
     
   	//出库单行单击事件
     //table.on('row(tableDetails)', function(obj) {
     	//$("#subTable").show();
         /* var data = obj.data;
         console.log(obj.data.id);
         table.render({
         	elem: '#tableDetailsSub'
             ,url:'${pageContext.request.contextPath }/receiveDetail/queryWorkloadByreceiveDetailQualityId.do?receiveDetailQuality_id=' + obj.data.id
             ,title: 'machineList'
             //,limits:[10,20,30]
             ,cols:
					[[
                     {field:'id', title:'序号', sort: true, width: 60, type:'numbers', align:'center'},
                     {field:'workman',title:'工作人员', align:'center'},
                     {field:'good_num',title:'操作良品数量', align:'center'},
                     {field:'ngood_num',title:'操作不良品数量', align:'center'}
                 ]]
             ,page: false
			}); */
        /*  table.render({
             elem: '#tableDetailsSub'
             ,url:'${pageContext.request.contextPath }/receiveDetail/queryWorkloadByreceiveDetailQualityId.do?receiveDetailQuality_id=' + obj.data.id
             ,toolbar: '#toolbar'
             ,title: '质检详细表'
             ,id :'contenttable1'
             ,limits:[10,20,30]
             ,defaultToolbar:['filter', 'print']
             ,cols:
				[[
                     {field:'id', title:'序号', sort: true, width: 60, type:'numbers', align:'center'},
                     {field:'workman',title:'工作人员', align:'center'},
                     {field:'good_num',title:'操作良品数量', align:'center'},
                     {field:'ngood_num',title:'操作不良品数量', align:'center'}
                 ]]
             ,page: true
             ,done : function(){
                 $('th').css({
                     'background-color': '#009688', 'color': '#fff','font-weight':'bold',
                 })
             }
         });
     }); */
     
   	 //表格行折叠方法
     function collapseTable(options) {
         var trObj = options.elem;
         if (!trObj) {
             return;
         }
         var accordion = options.accordion,
             success = options.success,
             content = options.content || '';
         var tableView = trObj.parents('.layui-table-view'); //当前表格视图
         var id = tableView.attr('lay-id'); //当前表格标识
         var index = trObj.data('index'); //当前行索引
         var leftTr = tableView.find('.layui-table-fixed.layui-table-fixed-l tr[data-index="' + index + '"]'); //左侧当前固定行
         var rightTr = tableView.find('.layui-table-fixed.layui-table-fixed-r tr[data-index="' + index + '"]'); //右侧当前固定行
         var colspan = trObj.find('td').length; //获取合并长度
         var trObjChildren = trObj.next(); //展开行Dom
         var indexChildren = id + '-' + index + '-children'; //展开行索引
         var leftTrChildren = tableView.find('.layui-table-fixed.layui-table-fixed-l tr[data-index="' + indexChildren + '"]'); //左侧展开固定行
         var rightTrChildren = tableView.find('.layui-table-fixed.layui-table-fixed-r tr[data-index="' + indexChildren + '"]'); //右侧展开固定行
         var lw = leftTr.width() + 15; //左宽
         var rw = rightTr.width() + 15; //右宽
         //不存在就创建展开行
         if (trObjChildren.data('index') != indexChildren) {
             //装载HTML元素
             var tr = '<tr data-index="' + indexChildren + '"><td colspan="' + colspan + '"><div style="height: auto;padding-left:' + lw + 'px;padding-right:' + rw + 'px" class="layui-table-cell">' + content + '</div></td></tr>';
             trObjChildren = trObj.after(tr).next().hide(); //隐藏展开行
             var fixTr = '<tr data-index="' + indexChildren + '"></tr>';//固定行
             leftTrChildren = leftTr.after(fixTr).next().hide(); //左固定
             rightTrChildren = rightTr.after(fixTr).next().hide(); //右固定
         }
         //展开|折叠箭头图标
         trObj.find('td[lay-event="collapse"] i.layui-colla-icon').toggleClass("layui-icon-right layui-icon-down");
         //显示|隐藏展开行
         trObjChildren.toggle();
         //开启手风琴折叠和折叠箭头
         if (accordion) {
             trObj.siblings().find('td[lay-event="collapse"] i.layui-colla-icon').removeClass("layui-icon-down").addClass("layui-icon-right");
             trObjChildren.siblings('[data-index$="-children"]').hide(); //展开
             rightTrChildren.siblings('[data-index$="-children"]').hide(); //左固定
             leftTrChildren.siblings('[data-index$="-children"]').hide(); //右固定
         }
         success(trObjChildren, indexChildren); //回调函数
         heightChildren = trObjChildren.height(); //展开高度固定
         rightTrChildren.height(heightChildren + 115).toggle(); //左固定
         leftTrChildren.height(heightChildren + 115).toggle(); //右固定
     }
});
</script>
</body>
</html>

